package com.example.a26436.newpractise.project;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.a26436.newpractise.R;
import com.example.a26436.newpractise.practise2.ArticleEnity;

import java.util.List;

/**
 * Created by 26436 on 2020/9/27.
 */

public class Articleadapter extends RecyclerView.Adapter<Articleadapter.ArticleViewHolder>{

    private Context mContext;
    private List<ArticleEnity.DataBean.DatasBean> mlist;

    public Articleadapter(Context mContext, List<ArticleEnity.DataBean.DatasBean> mlist) {
        this.mContext = mContext;
        this.mlist = mlist;
    }

    @Override
    public ArticleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(mContext);
        View view = inflater.inflate(R.layout.item_article_adapter, parent,false);
        return new ArticleViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ArticleViewHolder holder, int position) {
        ArticleEnity.DataBean.DatasBean datasBean = mlist.get(position);
        holder.tvAuthor.setText(datasBean.getAuthor());
        holder.tvClassify.setText(datasBean.getSuperChapterName() + "/" + datasBean.getChapterName());
        holder.tvTitle.setText(datasBean.getTitle());
        holder.tvTime.setText(datasBean.getNiceDate());


    }

    @Override
    public int getItemCount() {
        return mlist.size();
    }

    public static class ArticleViewHolder extends RecyclerView.ViewHolder {


        TextView tvAuthor;
        TextView tvClassify;
        TextView tvTitle;
        TextView tvTime;

        public ArticleViewHolder(View itemView) {
            super(itemView);
            tvAuthor = itemView.findViewById(R.id.tv_author_item_article_adapter);
            tvClassify = itemView.findViewById(R.id.tv_classify_item_article_adapter);
            tvTitle = itemView.findViewById(R.id.tv_content_item_article_adapter);
            tvTime = itemView.findViewById(R.id.tv_time_item_article_adapter);

        }
    }
}

